﻿#region Copyright information
// 
// Copyright © 2005-2013 Yongkee Cho. All rights reserved.
// 
// This code is a part of the Biological Object Library and governed under the terms of the
// GNU Lesser General  Public License (LGPL) version 2.1 which accompanies this distribution.
// For more information on the LGPL, please visit http://bol.codeplex.com/license.
// 
// - Filename: Division.cs
// - Author: Yongkee Cho
// - Email: yongkeecho@gmail.com
// - Date Created: 2013-01-25 3:25 PM
// - Last Modified: 2013-01-25 3:59 PM
// 
#endregion
using System;
using System.Globalization;
using System.Runtime.Serialization;

namespace BOL.Models.Taxonomy
{
    [DataContract]
    public struct Division : IIdentifiable<int>, INamed, IEquatable<Division>, ICloneable
    {
        #region Public properties

        /// <summary>Gets the id of division.</summary>
        [DataMember]
        public int Id { get; private set; }
        string IIdentifiable.Id { get { return Id.ToString(CultureInfo.InvariantCulture); } } 
        
        /// <summary>Gets the code of division.</summary>
        [DataMember]
        public string Code { get; private set; }

        /// <summary>Gets the name of division.</summary>
        [DataMember]
        public string Name { get; set; }

        #endregion

        #region Constructors

        public Division(int id, string code, string name)
            : this()
        {
            if (String.IsNullOrEmpty(code))
                throw new ArgumentNullException("code", "Code cannot be null or empty.");
            if (String.IsNullOrEmpty(name))
                throw new ArgumentNullException("name", "Name cannot be null or empty.");

            Id = id;
            Code = code;
            Name = name;
        }

        #endregion

        #region ICloneable implementation

        /// <summary>
        /// Creates an exact copy of current Division.
        /// </summary>
        /// <returns></returns>
        public Division Clone()
        {
            return new Division(Id, Code, Name);
        }

        /// <summary>
        /// Creates an exact copy of current Division as an object. 
        /// </summary>
        /// <returns></returns>
        object ICloneable.Clone()
        {
            return Clone();
        }

        #endregion

        #region IEquatable<Division> implementation

        public bool Equals(Division other)
        {
            return Id.Equals(other.Id);
        }

        #endregion

        #region Object overriden

        public override int GetHashCode()
        {
            return Id; 
        }
        
        public override bool Equals(object other)
        { 
            if (other is Division)
                return Equals((Division)other);

            return false;
        }

        public override string ToString()
        {
            return Name;
        }

        #endregion
    }
}
